package com.eschool.beans;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

import com.eschool.beans.datamodels.CustomerDataModel;
import com.eschool.dao.SchoolDao;
import com.eschool.model.School;
import com.eschool.service.CustomerService;
import com.eschool.service.impl.CustomerServiceImpl;

@ManagedBean(name="customerStatusUpdateBean")
@ViewScoped
public class CustomerStatusUpdateBean {
	
	private School[] selectedCustomersList;

    private CustomerDataModel customersModel;

	CustomerService service = new CustomerServiceImpl();
	
	private static List<School> cutomers;
	
	private boolean newStatus;

	public boolean isNewStatus() {
		return newStatus;
	}

	public void setNewStatus(boolean newStatus) {
		this.newStatus = newStatus;
	}

	public CustomerStatusUpdateBean() {
		cutomers = new ArrayList<School>();
		
		cutomers = SchoolDao.getSchools(null);

		customersModel = new CustomerDataModel(cutomers);
	}
	
    public School[] getSelectedCustomersList() {
		return selectedCustomersList;
	}

	public void setSelectedCustomersList(School[] selectedCustomersList) {
		this.selectedCustomersList = selectedCustomersList;
	}

	public CustomerDataModel getCustomersModel() {
		return customersModel;
	}

	public void setCustomersModel(CustomerDataModel customersModel) {
		this.customersModel = customersModel;
	}

	public static List<School> getCutomers() {
		return cutomers;
	}

	public static void setCutomers(List<School> cutomers) {
		CustomerStatusUpdateBean.cutomers = cutomers;
	}

	public String perform(){
    	
    	List selectedCustomers = Arrays.asList(selectedCustomersList);

    	service.updateCustomerStatus(selectedCustomers, newStatus);
    	
    	FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(
    					FacesMessage.SEVERITY_INFO,"Info message", "Customers' Status Updated"));
    	
    	return "customerStatusUpdate";
    }
}
